﻿namespace JobButenko.Models.BusinessLogicLayer
{
    using System.Configuration;

    public class DataManager
    {
        private readonly JobDataContext dataContext;


        private CandidateRepository candidateRepository;
        private EmployedJobRepository employedJobRepository;
        private EmployerRepository employerRepository;
        private PostRepository postRepository;
        private ProfessionalFieldRepository professionalFieldRepository;
        private ResumeDocRepository resumeDocRepository;
        private ResumeRepository resumeRepository;
        private RoleRepository roleRepository;
        private SalaryRepository salaryRepository;
        private UserRepository userRepository;
        private VacancyRepository vacancyRepository;

        public DataManager() : this(ConfigurationManager.ConnectionStrings[1].ConnectionString)
        {
        }

        public DataManager(string connectionString)
        {
            this.dataContext = new JobDataContext(connectionString);
        }


        public CandidateRepository Candidate
        {
            get { return this.candidateRepository ?? (this.candidateRepository = new CandidateRepository(this.dataContext)); }
        }

        public EmployedJobRepository EmployedJob
        {
            get { return this.employedJobRepository ?? (this.employedJobRepository = new EmployedJobRepository(this.dataContext)); }
        }

        public EmployerRepository Employer
        {
            get { return this.employerRepository ?? (this.employerRepository = new EmployerRepository(this.dataContext)); }
        }

        public PostRepository Post
        {
            get { return this.postRepository ?? (this.postRepository = new PostRepository(this.dataContext)); }
        }

        public ProfessionalFieldRepository ProfessionalField
        {
            get
            {
                return this.professionalFieldRepository ??
                       (this.professionalFieldRepository = new ProfessionalFieldRepository(this.dataContext));
            }
        }

        public ResumeRepository Resume
        {
            get { return this.resumeRepository ?? (this.resumeRepository = new ResumeRepository(this.dataContext)); }
        }

        public ResumeDocRepository ResumeDoc
        {
            get { return this.resumeDocRepository ?? (this.resumeDocRepository = new ResumeDocRepository(this.dataContext)); }
        }

        public RoleRepository Role
        {
            get { return this.roleRepository ?? (this.roleRepository = new RoleRepository(this.dataContext)); }
        }

        public SalaryRepository Salary
        {
            get { return this.salaryRepository ?? (this.salaryRepository = new SalaryRepository(this.dataContext)); }
        }

        public UserRepository User
        {
            get { return this.userRepository ?? (this.userRepository = new UserRepository(this.dataContext)); }
        }

        public VacancyRepository Vacancy
        {
            get { return this.vacancyRepository ?? (this.vacancyRepository = new VacancyRepository(this.dataContext)); }
        }
    }
}